﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Application.Website.ActionFilter
{
    public class AdminAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var staffAuth = filterContext.HttpContext.Request.Cookies[AuthenticationService.StaffAuthCookieName];

            if (staffAuth == null)
            {
                string pathToRedirect = filterContext.HttpContext.Request.Url.AbsolutePath;

                string urlToRedirect = string.Format("~/account/login?returnUrl={0}", pathToRedirect);

                filterContext.HttpContext.Response.Redirect(urlToRedirect, true);
            }
        }
    }
}